package com.clkj.xiuzheng.controller;

import com.clkj.xiuzheng.pojo.CustomerVisit;
import com.clkj.xiuzheng.pojo.Warehouse;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.service.WarehouseService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/warehouse")
@Api(value = "/warehouse", tags = {"仓库管理"})
@CrossOrigin
public class WarehouseController {

    @Autowired
    WarehouseService warehouseService;

    @ApiOperation(value = "添加仓库")
    @PostMapping("/addWarehouse")
    public Result addWarehouse(@RequestBody Warehouse warehouse) {
        try {
            warehouseService.addWarehouse(warehouse);
            return new Result(true, StatusCode.OK, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }

    }
    @ApiOperation(value = "获取所有仓库")
    @PostMapping("/getWarehouse")
    public Result getWarehouse(@RequestParam Integer pageSize,
                               @RequestParam Integer pageNum,Integer companyId) {
        try {
            PageInfo pageInfo= warehouseService.getWarehouse(pageSize, pageNum,companyId);
            return new Result(true, StatusCode.OK, "查询成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }

    }
    @ApiOperation(value = "修改仓库状态下线、上线")
    @PostMapping("/updateWarehouseDown")
    public Result updateWarehouseDown(@RequestParam Integer warehouseId,Integer status) {
        try {
            warehouseService.updateWarehouseDown(warehouseId,status);
            return new Result(true, StatusCode.OK, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "修改失败");
        }
    }
    @ApiOperation(value = "修改仓库状态上线")
    @PostMapping("/updateWarehouseUp")
    public Result updateWarehouseUp(@RequestParam Integer warehouseId) {
        try {
            warehouseService.updateWarehouseUp(warehouseId);
            return new Result(true, StatusCode.OK, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "修改失败");
        }
    }
    @ApiOperation(value = "根据仓库名称查询仓库")
    @PostMapping("/getWarehouseByName")
    public Result getWarehouseByName(@RequestParam Integer pageSize,
                                @RequestParam Integer pageNum,
                                @RequestParam String  warehouseName,
                                     Integer companyId) {
        try {
            PageInfo pageInfo= warehouseService.getWarehouseByName(pageSize, pageNum,warehouseName,companyId);
            return new Result(true, StatusCode.OK, "查询成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }

    }

}
